from xiangmu.page.base_page import BasePage


class LoginPage(BasePage):

    # 元素定位方式
    account_loc = ("x", '//*[@id="theForm"]/div/div[1]/div[2]/div[1]/input')
    password_loc = ('x', '//*[@id="theForm"]/div/div[1]/div[2]/div[2]/input')
    code_loc = ('x', '//*[@id="theForm"]/div/div[1]/div[2]/div[3]/input')
    submit_loc = ('x', '//*[@id="theForm"]/div/div[1]/div[2]/div[5]/span/input')
    # quit_loc =
    # fail_loc=eval(config['LoginPage']['fail_loc'])
    # realname_loc = eval(config['LoginPage']['realname_loc'])
    # tip_loc = eval(config['LoginPage']['tip_loc'])

    def login(self, username='admin', password='123456'):
        self.open("http://192.168.124.48/index.php/Admin/Admin/login")

        # 登陆
        self.type(*self.account_loc, username)
        self.type(*self.password_loc, password)
        self.click(*self.submit_loc)

    # def click_quit(self):
    #     """单击退出"""
    #     self.click(*self.quit_loc)
    #
    # def click_fail(self):
    #     '''登陆失败点击确定重新输入'''
    #     self.click(*self.fail_loc)
    #
    # def get_realname(self):
    #     """获取用户真名"""
    #     return self.locate_element(*self.realname_loc).text
    #
    # def get_tip(self):
    #     """获取登陆失败提示"""
    #     return self.locate_element(*self.tip_loc).text


if __name__ == '__main__':
    LoginPage('Chrome').login()